package de.slothsoft.commons.swing.util;

import java.awt.event.KeyEvent;

public final class KeyUtil {

	public static String getKeyName(int keyCode) {
		if (keyCode >= KeyEvent.VK_0 && keyCode <= KeyEvent.VK_9 || keyCode >= KeyEvent.VK_A
				&& keyCode <= KeyEvent.VK_Z) {
			return String.valueOf((char) keyCode);
		}

		String id = null;
		switch (keyCode) {
		case KeyEvent.VK_COMMA:
			id = "COMMA";
			break;
		case KeyEvent.VK_PERIOD:
			id = "PERIOD";
			break;
		case KeyEvent.VK_SLASH:
			id = "SLASH";
			break;
		case KeyEvent.VK_SEMICOLON:
			id = "SEMICOLON";
			break;
		case KeyEvent.VK_EQUALS:
			id = "EQUALS";
			break;
		case KeyEvent.VK_OPEN_BRACKET:
			id = "OPEN_BRACKET";
			break;
		case KeyEvent.VK_BACK_SLASH:
			id = "BACK_SLASH";
			break;
		case KeyEvent.VK_CLOSE_BRACKET:
			id = "CLOSE_BRACKET";
			break;

		case KeyEvent.VK_ENTER:
			id = "ENTER";
			break;
		case KeyEvent.VK_BACK_SPACE:
			id = "BACK_SPACE";
			break;
		case KeyEvent.VK_TAB:
			id = "TAB";
			break;
		case KeyEvent.VK_CANCEL:
			id = "CANCEL";
			break;
		case KeyEvent.VK_CLEAR:
			id = "CLEAR";
			break;
		case KeyEvent.VK_SHIFT:
			id = "SHIFT";
			break;
		case KeyEvent.VK_CONTROL:
			id = "CONTROL";
			break;
		case KeyEvent.VK_ALT:
			id = "ALT";
			break;
		case KeyEvent.VK_PAUSE:
			id = "PAUSE";
			break;
		case KeyEvent.VK_CAPS_LOCK:
			id = "CAPS_LOCK";
			break;
		case KeyEvent.VK_ESCAPE:
			id = "ESCAPE";
			break;
		case KeyEvent.VK_SPACE:
			id = "SPACE";
			break;
		case KeyEvent.VK_PAGE_UP:
			id = "PAGE_UP";
			break;
		case KeyEvent.VK_PAGE_DOWN:
			id = "PAGE_DOWN";
			break;
		case KeyEvent.VK_END:
			id = "END";
			break;
		case KeyEvent.VK_HOME:
			id = "HOME";
			break;
		case KeyEvent.VK_LEFT:
			id = "LEFT";
			break;
		case KeyEvent.VK_UP:
			id = "UP";
			break;
		case KeyEvent.VK_RIGHT:
			id = "RIGHT";
			break;
		case KeyEvent.VK_DOWN:
			id = "DOWN";
			break;

		// numpad numeric keys handled below
		case KeyEvent.VK_MULTIPLY:
			id = "MULTIPLY";
			break;
		case KeyEvent.VK_ADD:
			id = "ADD";
			break;
		case KeyEvent.VK_SEPARATOR:
			id = "SEPARATOR";
			break;
		case KeyEvent.VK_SUBTRACT:
			id = "SUBTRACT";
			break;
		case KeyEvent.VK_DECIMAL:
			id = "DECIMAL";
			break;
		case KeyEvent.VK_DIVIDE:
			id = "DIVIDE";
			break;
		case KeyEvent.VK_DELETE:
			id = "DELETE";
			break;
		case KeyEvent.VK_NUM_LOCK:
			id = "NUM_LOCK";
			break;
		case KeyEvent.VK_SCROLL_LOCK:
			id = "SCROLL_LOCK";
			break;

		case KeyEvent.VK_F1:
			id = "F1";
			break;
		case KeyEvent.VK_F2:
			id = "F2";
			break;
		case KeyEvent.VK_F3:
			id = "F3";
			break;
		case KeyEvent.VK_F4:
			id = "F4";
			break;
		case KeyEvent.VK_F5:
			id = "F5";
			break;
		case KeyEvent.VK_F6:
			id = "F6";
			break;
		case KeyEvent.VK_F7:
			id = "F7";
			break;
		case KeyEvent.VK_F8:
			id = "F8";
			break;
		case KeyEvent.VK_F9:
			id = "F9";
			break;
		case KeyEvent.VK_F10:
			id = "F10";
			break;
		case KeyEvent.VK_F11:
			id = "F11";
			break;
		case KeyEvent.VK_F12:
			id = "F12";
			break;
		case KeyEvent.VK_F13:
			id = "F13";
			break;
		case KeyEvent.VK_F14:
			id = "F14";
			break;
		case KeyEvent.VK_F15:
			id = "F15";
			break;
		case KeyEvent.VK_F16:
			id = "F16";
			break;
		case KeyEvent.VK_F17:
			id = "F17";
			break;
		case KeyEvent.VK_F18:
			id = "F18";
			break;
		case KeyEvent.VK_F19:
			id = "F19";
			break;
		case KeyEvent.VK_F20:
			id = "F20";
			break;
		case KeyEvent.VK_F21:
			id = "F21";
			break;
		case KeyEvent.VK_F22:
			id = "F22";
			break;
		case KeyEvent.VK_F23:
			id = "F23";
			break;
		case KeyEvent.VK_F24:
			id = "F24";
			break;

		case KeyEvent.VK_PRINTSCREEN:
			id = "PRINTSCREEN";
			break;
		case KeyEvent.VK_INSERT:
			id = "INSERT";
			break;
		case KeyEvent.VK_HELP:
			id = "HELP";
			break;
		case KeyEvent.VK_META:
			id = "META";
			break;
		case KeyEvent.VK_BACK_QUOTE:
			id = "BACK_QUOTE";
			break;
		case KeyEvent.VK_QUOTE:
			id = "QUOTE";
			break;

		case KeyEvent.VK_KP_UP:
			id = "KP_UP";
			break;
		case KeyEvent.VK_KP_DOWN:
			id = "KP_DOWN";
			break;
		case KeyEvent.VK_KP_LEFT:
			id = "KP_LEFT";
			break;
		case KeyEvent.VK_KP_RIGHT:
			id = "KP_RIGHT";
			break;

		case KeyEvent.VK_DEAD_GRAVE:
			id = "DEAD_GRAVE";
			break;
		case KeyEvent.VK_DEAD_ACUTE:
			id = "DEAD_ACUTE";
			break;
		case KeyEvent.VK_DEAD_CIRCUMFLEX:
			id = "DEAD_CIRCUMFLEX";
			break;
		case KeyEvent.VK_DEAD_TILDE:
			id = "DEAD_TILDE";
			break;
		case KeyEvent.VK_DEAD_MACRON:
			id = "DEAD_MACRON";
			break;
		case KeyEvent.VK_DEAD_BREVE:
			id = "DEAD_BREVE";
			break;
		case KeyEvent.VK_DEAD_ABOVEDOT:
			id = "DEAD_ABOVEDOT";
			break;
		case KeyEvent.VK_DEAD_DIAERESIS:
			id = "DEAD_DIAERESIS";
			break;
		case KeyEvent.VK_DEAD_ABOVERING:
			id = "DEAD_ABOVERING";
			break;
		case KeyEvent.VK_DEAD_DOUBLEACUTE:
			id = "DEAD_DOUBLEACUTE";
			break;
		case KeyEvent.VK_DEAD_CARON:
			id = "DEAD_CARON";
			break;
		case KeyEvent.VK_DEAD_CEDILLA:
			id = "DEAD_CEDILLA";
			break;
		case KeyEvent.VK_DEAD_OGONEK:
			id = "DEAD_OGONEK";
			break;
		case KeyEvent.VK_DEAD_IOTA:
			id = "DEAD_IOTA";
			break;
		case KeyEvent.VK_DEAD_VOICED_SOUND:
			id = "DEAD_VOICED_SOUND";
			break;
		case KeyEvent.VK_DEAD_SEMIVOICED_SOUND:
			id = "DEAD_SEMIVOICED_SOUND";
			break;

		case KeyEvent.VK_AMPERSAND:
			id = "AMPERSAND";
			break;
		case KeyEvent.VK_ASTERISK:
			id = "ASTERISK";
			break;
		case KeyEvent.VK_QUOTEDBL:
			id = "QUOTEDBL";
			break;
		case KeyEvent.VK_LESS:
			id = "LESS";
			break;
		case KeyEvent.VK_GREATER:
			id = "GREATER";
			break;
		case KeyEvent.VK_BRACELEFT:
			id = "BRACELEFT";
			break;
		case KeyEvent.VK_BRACERIGHT:
			id = "BRACERIGHT";
			break;
		case KeyEvent.VK_AT:
			id = "AT";
			break;
		case KeyEvent.VK_COLON:
			id = "COLON";
			break;
		case KeyEvent.VK_CIRCUMFLEX:
			id = "CIRCUMFLEX";
			break;
		case KeyEvent.VK_DOLLAR:
			id = "DOLLAR";
			break;
		case KeyEvent.VK_EURO_SIGN:
			id = "EURO_SIGN";
			break;
		case KeyEvent.VK_EXCLAMATION_MARK:
			id = "EXCLAMATION_MARK";
			break;
		case KeyEvent.VK_INVERTED_EXCLAMATION_MARK:
			id = "INVERTED_EXCLAMATION_MARK";
			break;
		case KeyEvent.VK_LEFT_PARENTHESIS:
			id = "LEFT_PARENTHESIS";
			break;
		case KeyEvent.VK_NUMBER_SIGN:
			id = "NUMBER_SIGN";
			break;
		case KeyEvent.VK_MINUS:
			id = "MINUS";
			break;
		case KeyEvent.VK_PLUS:
			id = "PLUS";
			break;
		case KeyEvent.VK_RIGHT_PARENTHESIS:
			id = "RIGHT_PARENTHESIS";
			break;
		case KeyEvent.VK_UNDERSCORE:
			id = "UNDERSCORE";
			break;

		case KeyEvent.VK_FINAL:
			id = "FINAL";
			break;
		case KeyEvent.VK_CONVERT:
			id = "CONVERT";
			break;
		case KeyEvent.VK_NONCONVERT:
			id = "NONCONVERT";
			break;
		case KeyEvent.VK_ACCEPT:
			id = "ACCEPT";
			break;
		case KeyEvent.VK_MODECHANGE:
			id = "MODECHANGE";
			break;
		case KeyEvent.VK_KANA:
			id = "KANA";
			break;
		case KeyEvent.VK_KANJI:
			id = "KANJI";
			break;
		case KeyEvent.VK_ALPHANUMERIC:
			id = "ALPHANUMERIC";
			break;
		case KeyEvent.VK_KATAKANA:
			id = "KATAKANA";
			break;
		case KeyEvent.VK_HIRAGANA:
			id = "HIRAGANA";
			break;
		case KeyEvent.VK_FULL_WIDTH:
			id = "FULL_WIDTH";
			break;
		case KeyEvent.VK_HALF_WIDTH:
			id = "HALF_WIDTH";
			break;
		case KeyEvent.VK_ROMAN_CHARACTERS:
			id = "ROMAN_CHARACTERS";
			break;
		case KeyEvent.VK_ALL_CANDIDATES:
			id = "ALL_CANDIDATES";
			break;
		case KeyEvent.VK_PREVIOUS_CANDIDATE:
			id = "PREVIOUS_CANDIDATE";
			break;
		case KeyEvent.VK_CODE_INPUT:
			id = "CODE_INPUT";
			break;
		case KeyEvent.VK_JAPANESE_KATAKANA:
			id = "JAPANESE_KATAKANA";
			break;
		case KeyEvent.VK_JAPANESE_HIRAGANA:
			id = "JAPANESE_HIRAGANA";
			break;
		case KeyEvent.VK_JAPANESE_ROMAN:
			id = "JAPANESE_ROMAN";
			break;
		case KeyEvent.VK_KANA_LOCK:
			id = "KANA_LOCK";
			break;
		case KeyEvent.VK_INPUT_METHOD_ON_OFF:
			id = "INPUT_METHOD_ON_OFF";
			break;

		case KeyEvent.VK_AGAIN:
			id = "AGAIN";
			break;
		case KeyEvent.VK_UNDO:
			id = "UNDO";
			break;
		case KeyEvent.VK_COPY:
			id = "COPY";
			break;
		case KeyEvent.VK_PASTE:
			id = "PASTE";
			break;
		case KeyEvent.VK_CUT:
			id = "CUT";
			break;
		case KeyEvent.VK_FIND:
			id = "FIND";
			break;
		case KeyEvent.VK_PROPS:
			id = "PROPS";
			break;
		case KeyEvent.VK_STOP:
			id = "STOP";
			break;

		case KeyEvent.VK_COMPOSE:
			id = "COMPOSE";
			break;
		case KeyEvent.VK_ALT_GRAPH:
			id = "ALT_GRAPH";
			break;
		}

		if (id != null) {
			return KeyMessages.getString(id);
		}

		if (keyCode >= KeyEvent.VK_NUMPAD0 && keyCode <= KeyEvent.VK_NUMPAD9) {
			char c = (char) (keyCode - KeyEvent.VK_NUMPAD0 + '0');
			return KeyMessages.getString("NUMPAD", "" + c);
		}

		return KeyMessages.getString("UNKNOWN", Integer.toString(keyCode, 16));
	}

	private KeyUtil() {
		// hide this class
	}
}